﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class BilldetailDAO:IData<Billdetail> 
 	{
		public BilldetailDAO(String myconnecString) : base(myconnecString) { }

		public override int OnSubmit(Billdetail item, int t) {
			 return connec.ExecuteNonQuery("sp_Billdetail", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + Billdetail.c_id, item.id), new SqlParameter("@" + Billdetail.c_billId, item.billId),
				 new SqlParameter("@" + Billdetail.c_productId, item.productId), new SqlParameter("@" + Billdetail.c_numberOf, item.numberOf),
				 new SqlParameter("@" + Billdetail.c_unitPriceUSD, item.unitPriceUSD), new SqlParameter("@" + Billdetail.c_rate, item.rate),
				 new SqlParameter("@" + Billdetail.c_unitPriceVND, item.unitPriceVND), new SqlParameter("@" + Billdetail.c_discount, item.discount),
				 new SqlParameter("@" + Billdetail.c_cash, item.cash), new SqlParameter("@" + Billdetail.c_orderId, item.orderId)); 
		}

		public override Billdetail GetItem(IDataReader dr)
		{
			Billdetail obj = new Billdetail();
			obj.id = Convert.ToInt64(dr[Billdetail.c_id]);
			obj.billId = Convert.ToInt64(dr[Billdetail.c_billId]);
			obj.productId = Convert.ToInt32(dr[Billdetail.c_productId]);
			obj.numberOf = Convert.ToInt32(dr[Billdetail.c_numberOf]);
			obj.unitPriceUSD = Convert.ToDecimal(dr[Billdetail.c_unitPriceUSD]);
			obj.rate = Convert.ToDecimal(dr[Billdetail.c_rate]);
			obj.unitPriceVND = Convert.ToDecimal(dr[Billdetail.c_unitPriceVND]);
			obj.discount = Convert.ToDecimal(dr[Billdetail.c_discount]);
			obj.cash = Convert.ToDecimal(dr[Billdetail.c_cash]);
			obj.orderId = Convert.ToInt32(dr[Billdetail.c_orderId]);
			return obj;
		}

		public override List<Billdetail> GetAll()
		{
			return GetAll("select * from " + Billdetail.b_Billdetail, CommandType.Text);
		}

		public override Billdetail GetItemById(object id)
		{
			throw new NotImplementedException();
		}

	}

 }
